package eco2automotive.gui.components;
import eco2automotive.util.InitData;
import eco2automotive.util.WorkingDirectory;
import eco2automotive.util.InitData_Statics;
import eco2automotive.data.Protocol;
import eco2automotive.port.ConnectionControl;
import eco2automotive.gui.actions.Act_btn_PROTOCOL_SET;
import javax.swing.*;
import java.awt.*;
import java.util.*;

/**  
  * Panel, display information TX/RX
  * @version 1.0
 * @author Fco Javier Sanchez Esparza
 */
public class Panel_PROTOCOL extends JPanel{
JComboBox jComboBox1;
JButton btn_PROTOCOL;
JLabel lbSelected;
ArrayList protocolos;
InitData ini;
String SELECTED;
/**
 * 
 * @param connControl ConnectionControl object
 * @param InfoLog Link to Panel InfoLog
 * @param txrx
 */
public Panel_PROTOCOL(ConnectionControl connControl, Panel_INFOLOG InfoLog, Panel_TxRx txrx){
    setBorder(new javax.swing.border.TitledBorder("Select Protocol"));  
    btn_PROTOCOL = new JButton("Select&Try");
    btn_PROTOCOL.addActionListener(new Act_btn_PROTOCOL_SET(connControl,InfoLog,txrx,this));
    lbSelected=new JLabel();   
    jComboBox1=new JComboBox();
    String directory=new WorkingDirectory().workingDirectoryJar().replace('\\', '/');
    String source=InitData_Statics.INITDATA_Directory_of_DATA_; 
    ini= new InitData();
//--------------------------------------Leemeos tabla de protocolos
    source=source+InitData_Statics.INITDATA_NAMEof_Protocols_DAT;   
   protocolos=ini.loadDataProtocol(directory+source);
   for ( Iterator iterador = protocolos.listIterator(); iterador.hasNext(); ) {
                  Protocol p = (Protocol) iterador.next();
                  jComboBox1.addItem(p.getDescription());
    }
   
 lbSelected.setText(jComboBox1.getItemAt(0).toString());
 SELECTED=lbSelected.getText();
 
 this.setLayout (new BorderLayout());
     
this.add (jComboBox1, BorderLayout.CENTER);

this.add(btn_PROTOCOL,BorderLayout.EAST);

this.add(lbSelected,BorderLayout.SOUTH);

    }
/**
 * 
 */
public void setSelectedProtocol(){
    SELECTED=this.jComboBox1.getSelectedItem().toString();
    this.lbSelected.setText(SELECTED);
}
/**
 * 
 * @return
 */
public String getSelectedProtocol(){return this.SELECTED;}
/**
 * 
 * @return
 */
public int getIDofSelectedProtocol(){return this.jComboBox1.getSelectedIndex();}    
}
